//
//  EventListViewControlController.m
//  HaiGoumerMerchant
//
//  Created by apple on 17/1/18.
//  Copyright © 2017年 com.zaoguankeji.www. All rights reserved.
//

#import "EventListViewControlController.h"

#import "EventListViewController.h"
#import "AddEventViewController.h"
@interface EventListViewControlController ()<UITextFieldDelegate, CAPSPageMenuDelegate>
@property (nonatomic, strong) CAPSPageMenu *pageMenu;
@property(nonatomic, strong) UITextField * searchTF;
@property(nonatomic, assign) NSInteger index;
@end

@implementation EventListViewControlController

- (void)viewDidLoad {
    [super viewDidLoad];
        self.title = @"活动列表";
    [self configureEventListPageMenu];
    [self setEventListViewControllerItems];
    [self.view addSubview:self.searchTF];
    // Do any additional setup after loading the view.
}

- (UIView *)searchTF {
    if(_searchTF == nil) {
        
        //    self.searchView  = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        //        _searchView.backgroundColor = [UIColor colorWithRed:237/255.0 green:239/255.0 blue:240/255.0 alpha:1];
        
        UITextField *searchTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 8, self.view.bounds.size.width - 10 * 2, 44 - 5*2)];
        searchTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        UIImageView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
        rightView.frame = CGRectMake(-20, 0, 30, searchTF.frame.size.height - 15);
        searchTF.rightView = rightView;
        searchTF.borderStyle = UITextBorderStyleRoundedRect;
        searchTF.backgroundColor = [UIColor whiteColor];
        searchTF.rightViewMode = UITextFieldViewModeUnlessEditing;
        searchTF.returnKeyType = UIReturnKeySearch;
        searchTF.placeholder = @"请输入关键词或手机号";
        //        [_searchView addSubview:searchTF];
        searchTF.delegate = self;
        self.searchTF = searchTF;
    }
    
    return  _searchTF;
}

#pragma mark ------------------------ UItextfield
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (self.returnTextBlock) {
        _returnTextBlock(textField.text, self.index);
    }
    [textField resignFirstResponder];
    
    return YES;
}
-(void)setEventListViewControllerItems{
    UIBarButtonItem *rightBackButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fanghui"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(gotoPreferences)];
    self.navigationItem.leftBarButtonItem = rightBackButton;
    
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    UIBarButtonItem *righAddtBackButton = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonSystemItemAdd target:self action:@selector(addBtnAction)];
    self.navigationItem.rightBarButtonItem = righAddtBackButton;
}

//MARK: gotoPreferences
- (void)gotoPreferences {
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (void)addBtnAction {
    AddEventViewController *addvc = [UIStoryboard loadStoryboard:AddEventViewControllerID];
    addvc.hidesBottomBarWhenPushed =YES;
    [self.navigationController pushViewController:addvc animated:YES];
    
}- (void)configureEventListPageMenu {
    EventListViewController *allVC = [UIStoryboard loadStoryboard:EventListViewControllerID];
    
    allVC.title = @"全部";
     allVC.myNavVC = self.navigationController;
    EventListViewController *underwayVC = [UIStoryboard loadStoryboard:EventListViewControllerID];
    
    underwayVC.title = @"进行中";
    underwayVC.myNavVC = self.navigationController;
    EventListViewController *startVC = [UIStoryboard loadStoryboard:EventListViewControllerID];
    
    startVC.title = @"未开始";
    startVC.myNavVC = self.navigationController;
    EventListViewController *downVC = [UIStoryboard loadStoryboard:EventListViewControllerID];
   
    downVC.title = @"已下线";
    downVC.myNavVC = self.navigationController;
    NSArray *controllerArray = @[allVC, underwayVC, startVC, downVC];
    NSDictionary *parameters = @{
                                 CAPSPageMenuOptionScrollMenuBackgroundColor: [UIColor colorWithRed:30.0/255.0 green:30.0/255.0 blue:30.0/255.0 alpha:1.0],
                                 CAPSPageMenuOptionViewBackgroundColor: [UIColor colorWithRed:20.0/255.0 green:20.0/255.0 blue:20.0/255.0 alpha:1.0],
                                 CAPSPageMenuOptionSelectionIndicatorColor: [UIColor orangeColor],
                                 CAPSPageMenuOptionBottomMenuHairlineColor: [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:70.0/255.0 alpha:1.0],
                                 CAPSPageMenuOptionMenuItemFont: [UIFont fontWithName:@"HelveticaNeue" size:13.0],
                                 CAPSPageMenuOptionMenuHeight: @(40.0),
                                 CAPSPageMenuOptionMenuItemWidth: @(90.0),
                                 CAPSPageMenuOptionCenterMenuItems: @(YES)
                                 };
    
    _pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 44.0, self.view.frame.size.width, self.view.frame.size.height) options:parameters ];
    _pageMenu.delegate = self;
    [self.view addSubview:_pageMenu.view];
    [self.pageMenu addPageAtIndex:0];
}
- (void)willMoveToPage:(UIViewController *)controller index:(NSInteger)index {
    EventListViewController *contr = (EventListViewController *) controller;
    self.index = index;
    contr.controlVC = self;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
